<template>
    <div>
        <div class="header">
            投诉建议列表
        </div>
        <div style="padding:0 30px">
            <el-form ref="form" :model="form" label-width="80px">
                <div class="top">
                    <el-form-item label="投诉标题" label-width="80px">
                        <el-input v-model="query.name" style="width:180px" placeholder="投诉标题"></el-input>
                    </el-form-item>
                    <el-form-item label="地址" label-width="50px">
                        <el-input v-model="query.address" style="width:180px" placeholder="地址"></el-input>
                    </el-form-item>
                    <el-form-item label="电话" label-width="50px">
                        <el-input v-model="query.tel" style="width:180px" placeholder="电话"></el-input>
                    </el-form-item>
                    <el-form-item label="按时间查询" label-width="90px">
                        <div class="block">
                            <el-date-picker v-model="value2" type="daterange" align="right" unlink-panels
                                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                                :picker-options="pickerOptions" style="width:240px">
                            </el-date-picker>
                        </div>
                    </el-form-item>
                    <el-form-item label="投诉状态" label-width="80px">
                        <el-select v-model="query.state" placeholder="请选择" style="width:130px">
                            <el-option v-for="item in state" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="投诉类型" label-width="80px">
                        <el-select v-model="query.type" placeholder="请选择" style="width:130px">
                            <el-option v-for="item in type" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="居民" label-width="50px" style="width:130px">
                        <el-input v-model="query.userid" style="width:180px" placeholder="电话"></el-input>
                    </el-form-item>

                </div>
                <el-button type="primary" style="width:100px" @click="onSubmit">查询</el-button>
            </el-form>
        </div>
        <!-- 批量删除 -->
        <div style="margin-top: 22px;padding:0 25px">
            <el-button type="danger">批量删除</el-button>
        </div>
        <!-- 列表 -->
        <div style="padding:20px">
            <Table :selection="selection" :tableCols="tableCols" :tableData="tableData" @pagechange="pagechange"
                :total="total">
                <!-- 投诉类型 -->
                <template #content="{ row }">
                    <el-link type="primary" @click="Details(row)">{{row.typename}}</el-link>
                </template>
                <template #option="{row}">
                    <el-button type="danger" @click=del(row.id)>删除</el-button>
                </template>
            </Table>
        </div>
        <!-- 详情 -->
        <div>
            <Details :dialogVisibles="dialogVisibles" :handleClickdata="handleClickdata" @iscloses="iscloses"></Details>
        </div>
    </div>
</template>

<script>
import Table from '@/components/Table/Table.vue'
import Details from '@/components/详情/repairsXQ.vue'
import { List, questionstate, questiontype } from '@/api/questions'
import { IMGURL } from '@/api/config'
export default {
    components: {
        Table,
        Details
    },
    data() {
        return {
            total: 0,
            IMGURL: IMGURL,
            selection: true,
            dialogVisibles: false,
            form: {

            },
            value2: 0,
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            tableCols: [
                {
                    prop: "id",
                    lable: "id",
                    width: 70
                },
                {
                    // prop: "typename",
                    lable: "问题类型",
                    coltype: "content",
                    slotname: "content"
                },
                {
                    prop: "address",
                    lable: "问题地址",
                },

                {
                    prop: "content",
                    lable: "问题描述",
                },
                {
                    prop: "statename",
                    lable: "处理状态",
                },
                {
                    prop: "username",
                    lable: "业主名称",
                },
                {
                    prop: "tel",
                    lable: "业主电话",
                },
                {
                    prop: "addtime",
                    lable: "维修日期",
                },
                {
                    lable: "操作",
                    coltype: "option",
                    slotname: "option",
                },
            ],
            tableData: [],
            query: {
                page: 1,
                psize: 5,
                key: ""
            },
            state: [],
            type: [],
            handleClickdata: {}
        }
    },
    created() {
        // 投诉列表
        this.getList()
        // 投诉类型
        this.getquestiontype()
        // 投诉状态
        this.getquestionstate()
    },
    methods: {
        // 投诉列表
        async getList() {
            let res = await List(this.query)
            console.log(res);
            if (res.errCode == 10000) {
                this.tableData = res.data.list
                this.total = res.data.counts
            }
        },
        // 投诉类型
        async getquestiontype() {
            let res = await questiontype()
            if (res.errCode == 10000) {
                this.type = res.data.list
            }
        },

        // 投诉状态
        async getquestionstate() {
            let res = await questionstate()
            if (res.errCode == 10000) {
                this.state = res.data.list
            }
        },
        onSubmit() {
            this.getList()
        },
        // 深拷贝
        // 数据的刷新
        iscloses(val, isrefresh = false, editdata = {}) {
            this.dialogVisibles = val
            this.handleClickdata = editdata
            if (isrefresh) {
                this.getList()
            }
        },
        Details(val) {
            this.handleClickdata = JSON.parse(JSON.stringify(val))
            this.dialogVisibles = true
        },
        // 分页
        pagechange(val) {
            this.query = val
            this.getList()
        }
    }
}
</script>

<style lang="less" scoped>
.header {
    display: flex;
    position: relative;
    padding: 0 10px;
    height: 50px;
    margin-bottom: 30px;
    border-bottom: 1px solid #eee;
    color: #427ff4;
    font-size: 16px;
}

.top {
    display: flex;

}
</style>       